package com.dule.Medic.pages;

import org.apache.tapestry5.annotations.InjectPage; 
import org.apache.tapestry5.annotations.OnEvent; 
import org.apache.tapestry5.annotations.Property; 
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.ioc.annotations.Inject;  

import com.dule.Medic.model.Doctor;
import com.dule.Medic.service.DoctorService;

public class ChangeDoctorInfo 
{
	@Property    	
	@SessionState     
	private Doctor doctor;     
	private boolean doctorExists;        
	
	@InjectPage  
	private DoctorInfo doctorInfo;   
	@Inject    
	private DoctorService doctorService;    
	
	public Object onActivate()
	{           
		if(doctorExists)
		{                
			return null;      
		}     
		return FirstPage.class;          
	}           
	
	@OnEvent(component="doctorUpdate")  
	public Object update()
	{          
		boolean changed=doctorService.changeDoctorInfo(doctor);  
		if(changed)
		{                       
			doctorInfo.onActivate();
			return doctorInfo;  
		}         
		else
		{      
			return this;     
		}    
	}  
}

